package com.funny.learning.english.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.funny.learning.english.BaseActivity;
import com.funny.learning.english.R;
import com.funny.learning.english.api.BaseAjaxCallBack.IAjaxCallbackMMK;
import com.funny.learning.english.api.Define;
import com.funny.learning.english.api.TiengAnhApi;
import com.funny.learning.english.util.ValidationUtil;

public class ForgotActivity extends BaseActivity {
	private EditText edtEmail;
	private Button btResetPass;
	private TextView tvMessage;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.forgot_layout);
		edtEmail = (EditText) findViewById(R.id.edtEmail);
		btResetPass = (Button) findViewById(R.id.btResetPass);
		tvMessage = (TextView)findViewById(R.id.tvMessage);
		btResetPass.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View paramView) {
				String email = edtEmail.getText().toString();
				if (!ValidationUtil.isValidEmail(email)) {
					tvMessage.setText(getString(R.string.register_err_email));
				}else{
					TiengAnhApi.forgotPass(email, activity, callbackAPI); 
				}

			}
		});
	}

	private IAjaxCallbackMMK callbackAPI = new IAjaxCallbackMMK() {

		@Override
		public <T> void handler(T t, int code) {
			if (code == COMPLETE) {
				Intent intent = new Intent(activity, GetPwdForgotActivity.class);
				Bundle bundle = new Bundle();
				bundle.putString(Define.KEY_EMAIL, edtEmail.getText().toString());
				intent.putExtras(bundle);
				startActivity(intent);
			} else if (code == ERROR) {
				tvMessage.setText(getString(R.string.forgot_not_exist_email));
			}
		}
	};
}
